package com.aigou.admin.aigouspringboot.service.impl;

import com.aigou.admin.aigouspringboot.common.Constants;
import com.aigou.admin.aigouspringboot.entity.ShopCartProduct;
import com.aigou.admin.aigouspringboot.mapper.ShopCartProductMapper;
import com.aigou.admin.aigouspringboot.service.ShopCartProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShopCartProductServerImpl implements ShopCartProductService {

    @Resource
    private ShopCartProductMapper shopCartProductMapper;

    @Override
    public List<ShopCartProduct> selectAll() {
        return shopCartProductMapper.selectAll();
    }

    @Override
    public PageInfo<ShopCartProduct> selectShopCartProductListByPage(Integer current) {
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        List<ShopCartProduct> shopCartProductList = shopCartProductMapper.selectAll();
        return new PageInfo<>(shopCartProductList);
    }

    @Override
    public int deleteById(String id) {
        return shopCartProductMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ShopCartProduct selectById(String id) {
        return shopCartProductMapper.selectByPrimaryKey(id);
    }

    @Override
    public int edit(ShopCartProduct shopCartProduct) {
        return shopCartProductMapper.updateByPrimaryKeySelective(shopCartProduct);
    }

    @Override
    public int save(ShopCartProduct shopCartProduct) {
        return shopCartProductMapper.insertSelective(shopCartProduct);
    }

    @Override
    public List<ShopCartProduct> selectByUserID(String userId) {
        return shopCartProductMapper.selectByUserId(userId);
    }

    // 根据购物车商品ID更新商品数量
    @Override
    public int updateProductNum(String id, Integer productNum) {
        return shopCartProductMapper.updateProductNum(id, productNum);
    }

    @Override
    public int deleteByIds(List<String> ids) {
        return shopCartProductMapper.deleteByPrimaryKeys(ids);
    }

}
